<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="button" onclick="disp_year()" value="请输入您的出生年份" />
    <script>
        function disp_year() {
            var year = prompt("请输入您的出生年份", "")
            if (year != null && year != "") {
                document.write("您今年" + (2021 - year) + "岁了")
            }
        }
    </script>

</body>

</html>